home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / othergnu / ispell.zoo / term.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-18  |  4.8 KB  |  276 lines

  1.  
  2. /* -*- Mode:Text -*- */
  3.  
  4. /*
  5.  * term.c - deal with termcap, and unix terminal mode settings
  6.  *
  7.  * Pace Willisson, 1983
  8.  */
  9.  
  10. #include <stdio.h>
  11. #ifdef USG
  12. #include <termio.h>
  13. #else
  14. #include <sgtty.h>
  15. #endif
  16. #include <signal.h>
  17. #include "config.h"
  18. #include "ispell.h"
  19.  
  20. #ifdef atarist
  21. #ifdef SIGTSTP
  22. #undef SIGTSTP
  23. #endif
  24. #endif
  25.  
  26. int putch();
  27.  
  28. erase ()
  29. {
  30.     if (cl)
  31.         tputs(cl, li, putch);
  32.     else {
  33.         if (ho)
  34.             tputs(ho, 100, putch);
  35.         else if (cm)
  36.             tputs(tgoto(cm, 0, 0), 100, putch);
  37.         tputs(cd, li, putch);
  38.     }
  39. }
  40.  
  41. move (row, col)
  42. {
  43.     tputs (tgoto (cm, col, row), 100, putch);
  44. }
  45.  
  46. inverse ()
  47. {
  48.     tputs (so, 10, putch);
  49. }
  50.  
  51. normal ()
  52. {
  53.     tputs (se, 10, putch);
  54. }
  55.  
  56. backup ()
  57. {
  58.     if (BC)
  59.         tputs (BC, 1, putch);
  60.     else
  61.         putchar ('\b');
  62. }
  63.  
  64. putch (c)
  65. {
  66.     putchar (c);
  67. }
  68.  
  69. #ifdef USG
  70. struct termio sbuf, osbuf;
  71. #else
  72. struct sgttyb sbuf, osbuf;
  73. struct ltchars ltc, oltc;
  74. #endif
  75. static termchanged = 0;
  76. static int (*oldint) ();
  77. static int (*oldterm) ();
  78. #ifdef SIGTTIN
  79. static int (*oldttin) ();
  80. static int (*oldttou) ();
  81. static int (*oldtstp) ();
  82. #endif
  83.  
  84. terminit ()
  85. {
  86.     int done();
  87.  
  88. #ifdef USG
  89.     if (!isatty(0)) {
  90.         fprintf (stderr, "Can't deal with non interactive use yet.\n");
  91.         exit (1);
  92.     }
  93.     ioctl (0, TCGETA, &osbuf);
  94.     termchanged = 1;
  95.  
  96.     sbuf = osbuf;
  97.     sbuf.c_lflag &= ~(ECHO | ECHOK | ECHONL | ICANON);
  98.     sbuf.c_oflag &= ~(OPOST);
  99.     sbuf.c_iflag &= ~(INLCR | IGNCR | ICRNL);
  100.     sbuf.c_cc[VMIN] = 1;
  101.     sbuf.c_cc[VTIME] = 1;
  102.     ioctl (0, TCSETAW, &sbuf);
  103.  
  104.     erasechar = osbuf.c_cc[VERASE];
  105.     killchar = osbuf.c_cc[VKILL];
  106.  
  107. #else
  108. #ifndef atarist
  109.     int tpgrp;
  110.     int onstop();
  111.     extern short ospeed;
  112. #endif
  113.  
  114.  
  115. retry:
  116. #ifdef SIGTSTP
  117.     sigsetmask(1<<(SIGTSTP-1) | 1<<(SIGTTIN-1) | 1<<(SIGTTOU-1));
  118. #endif
  119. #ifdef TIOCGPGRP
  120.     if (ioctl(0, TIOCGPGRP, &tpgrp) != 0) {
  121.         fprintf (stderr, "Can't deal with non interactive use yet.\n");
  122.         exit (1);
  123.     }
  124. #endif
  125. #ifdef SIGTSTP
  126.     if (tpgrp != getpgrp(0)) { /* not in foreground */
  127.         sigsetmask(1<<(SIGTSTP-1) | 1<<(SIGTTIN-1));
  128.         signal(SIGTTOU, SIG_DFL);
  129.         kill(0, SIGTTOU);
  130.         /* job stops here waiting for SIGCONT */
  131.         goto retry;
  132.     }
  133. #endif
  134.  
  135.     ioctl (0, TIOCGETP, &osbuf);
  136.     ioctl (0, TIOCGLTC, &oltc);
  137.     termchanged = 1;
  138.  
  139.     sbuf = osbuf;
  140.     sbuf.sg_flags &= ~ECHO;
  141.     sbuf.sg_flags |= TERM_MODE;
  142.     ioctl (0, TIOCSETP, &sbuf);
  143.  
  144.     erasechar = sbuf.sg_erase;
  145.     killchar = sbuf.sg_kill;
  146. #ifndef atarist
  147.     ospeed = sbuf.sg_ospeed;
  148. #endif
  149.  
  150.     ltc = oltc;
  151.     ltc.t_suspc = -1;
  152.     ioctl (0, TIOCSLTC, <c);
  153.  
  154.     if ((oldint = signal (SIGINT, SIG_IGN)) != SIG_IGN)
  155.         signal (SIGINT, done);
  156.     if ((oldterm = signal (SIGTERM, SIG_IGN)) != SIG_IGN)
  157.         signal (SIGTERM, done);
  158.  
  159. #ifdef SIGTTIN
  160.     sigsetmask(0);
  161.     if (signal (SIGTTIN, SIG_IGN) != SIG_IGN)
  162.         signal(SIGTTIN, onstop);
  163.     if (signal (SIGTTOU, SIG_IGN) != SIG_IGN)
  164.         signal(SIGTTOU, onstop);
  165.     if (signal (SIGTSTP, SIG_IGN) != SIG_IGN)
  166.         signal(SIGTSTP, onstop);
  167. #endif
  168. #endif
  169.  
  170.     tgetent(termcap, getenv("TERM"));
  171.     termptr = termstr;
  172.     bs = tgetflag("bs");
  173.     BC = tgetstr("bc", &termptr);
  174.     UP = tgetstr("up", &termptr);
  175.     cd = tgetstr("cd", &termptr);
  176.     ce = tgetstr("ce", &termptr);    
  177.     cl = tgetstr("cl", &termptr);
  178.     cm = tgetstr("cm", &termptr);
  179.     dc = tgetstr("dc", &termptr);
  180.     dl = tgetstr("dl", &termptr);
  181.     dm = tgetstr("dm", &termptr);
  182.     ed = tgetstr("ed", &termptr);
  183.     ei = tgetstr("ei", &termptr);
  184.     ho = tgetstr("ho", &termptr);
  185.     ic = tgetstr("ic", &termptr);
  186.     il = tgetstr("al", &termptr);
  187.     im = tgetstr("im", &termptr);
  188.     ip = tgetstr("ip", &termptr);
  189.     nd = tgetstr("nd", &termptr);
  190.     vb = tgetstr("vb", &termptr);
  191.     so = tgetstr("so", &termptr);    /* inverse video on */
  192.     se = tgetstr("se", &termptr);    /* inverse video off */
  193.     co = tgetnum("co");
  194.     li = tgetnum("li");    
  195.  
  196. }
  197.  
  198. done ()
  199. {
  200.     unlink (tempfile);
  201.     if (termchanged)
  202. #ifdef USG
  203.         ioctl (0, TCSETAW, &osbuf);
  204. #else
  205.         ioctl (0, TIOCSETP, &osbuf);
  206.         ioctl (0, TIOCSLTC, &oltc);
  207. #endif
  208.     exit (0);
  209. }
  210.  
  211. #if !defined(USG) && !defined(atarist)
  212. onstop(signo)
  213. int signo;
  214. {
  215.     ioctl (0, TIOCSETP, &osbuf);
  216.     ioctl (0, TIOCSLTC, &oltc);
  217.     signal(signo, SIG_DFL);
  218.     sigsetmask(sigblock(0) & ~(1 << (signo-1)));
  219.     kill(0, signo);
  220.     /* stop here until continued */
  221.     signal(signo, onstop);
  222.     ioctl (0, TIOCSETP, &sbuf);
  223.     ioctl (0, TIOCSLTC, <c);
  224. }
  225.  
  226. stop ()
  227. {
  228. #ifdef SIGTSTP
  229.     onstop (SIGTSTP);
  230. #endif
  231.     ;
  232. }
  233. #endif
  234.  
  235. shellescape (buf)
  236. char *buf;
  237. {
  238.  
  239. #ifdef USG
  240.     ioctl (0, TCSETAW, &osbuf);
  241. #else
  242.     ioctl (0, TIOCSETP, &osbuf);
  243.     ioctl (0, TIOCSLTC, &oltc);
  244. #endif
  245.     signal (SIGINT, oldint);
  246.     signal (SIGTERM, oldterm);
  247. #ifdef SIGTTIN
  248.     oldttin = signal(SIGTTIN, SIG_DFL);
  249.     oldttou = signal(SIGTTOU, SIG_DFL);
  250.     oldtstp = signal(SIGTSTP, SIG_DFL);
  251. #endif
  252.  
  253.     system (buf);
  254.  
  255.     if (signal (SIGINT, SIG_IGN) != SIG_IGN)
  256.         signal (SIGINT, done);
  257.     if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
  258.         signal (SIGTERM, done);
  259.  
  260. #ifdef SIGTTIN
  261.     signal(SIGTTIN, oldttin);
  262.     signal(SIGTTOU, oldttou);
  263.     signal(SIGTSTP, oldtstp);
  264. #endif
  265.  
  266. #ifdef USG
  267.     ioctl (0, TCSETAW, &sbuf);
  268. #else
  269.     ioctl (0, TIOCSETP, &sbuf);
  270.     ioctl (0, TIOCSLTC, <c);
  271. #endif
  272.     printf ("\n-- Type space to continue --");
  273.     fflush (stdout);
  274.     getchar ();
  275. }
  276.